<?php

class Rd_DOM_DOMNode
{
	
}

class Re_DOM_DocumentExtended extends DOMDocument
{
	/**
	 * Re_DOM_Element::getElementById()
	 * 
	 * Finds and returns the DOMElement with the specified attribute id.
	 * WARNING: php's DOMDocument DOES NOT look for the attribute id but the xml:id
	 * 
	 * @param mixed $id
	 * @return
	 */

	public function getElementById($id)
	{
		$xpath = new DOMXPath($this);
		$result = $xpath->query("//*[@id='$id']");
		return $result->item(0);
	}
}

/**
 * Re_DOM_Element
 * 
 * Re_DOM_Element is a decorator that tries to extend DOMElement's features without actuablly
 * extending the class.
 * This allows for changes in the original DOM Implementation that will not interfear with this class.
 * Also gives us the opportunatty to not include methods and options that will not be needed for the
 * purpose of Re_DOM_Element, which is mostly (and probably only) to help creating form elements.
 * 
 * DOMElement allows the creation, parsing  of complete XML documents and
 * 
 * @package 
 * @author Some weird name
 * @copyright 2008
 * @version $Id$
 * @access public
 */
class Re_DOM_Element
{
	protected $DOMDocument;
	protected $DOMElement;
	
	/**
	 * Re_DOM_Element::__construct()
	 * 
	 * @param mixed $DOMDocument
	 * @return
	 */
	 
	public function __construct($tagName, $value=null)
	{
		$this->DOMElement = new DOMElement($tagName, $value);
	}
	
	/** DOMElement Methods */
	
	public function getAttribute($name)
	{
		return $this->DOMElement->getAttribute($name);
	}
	
	public function getElementsByTagName($name)
	{
		return $this->DOMElement->getElementsByTagName($name);
	}
	
	public function hasAttribute($name)
	{
		return $this->DOMElement->hasAttribute($name);
	}
	
	public function removeAttribute($name)
	{
		return $this->DOMElement->removeAttribute($name);
	}
	
	public function setAttribute($name, $value)
	{
		return $this->DOMElement->setAttribute($name, $value);
	}
	
	public function setIdAttribute($name, $isId)
	{
		return $this->DOMElement->setIdAttribute($name, $isId);
	}
	
	/** DOMElement's Inherited methods */
	
	public function appendChild(DOMNode $newnode)
	{
		return $this->DOMElement->appendChild($newnode);
	}
	
	public function cloneNode(bool $deep)
	{
		return $this->DOMElement->cloneNode($deep);
	}
	
	public function hasAttributes()
	{
		return $this->DOMElement->hasAttributes();
	}
	
	public function hasChildNodes()
	{
		return $this->DOMElement->hasChildNodes();
	}
	
	public function insertBefore(DOMNode $newnode, DOMNode $refnode=null)
	{
		return $this->DOMElement->insertBefore($newnode, $refnode);
	}
	
	public function isSameNode (DOMNode $node)
	{
		return $this->DOMElement->isSameNode ($node);
	}
	
	public function isSupported(string $feature, string $version)
	{
		return $this->DOMElement->isSupported($feature, $version);
	}
	
	public function removeChild(DOMNode $oldnode)
	{
		return $this->DOMElement->removeChild($oldnode);
	}
	
	public function replaceChild(DOMNode $newnode, DOMNode $oldnode)
	{
		return $this->DOMElement->removeChild($newnode, $oldnode);
	}
	
}

$doc = new Re_DOM_DocumentExtended('1.0', 'utf-8');

//$form = $doc->createElement('form');
$form = new Re_DOM_Element('form');
$doc->appendChild($form);
$form->setAttribute('id', 'some-form');
$form->setAttribute('method', 'POST');

$doc->getElementById('some-form')->setAttribute('class', 'test-class');

echo $doc->saveHTML();

?>